//
//  SEGMonthCardRecordViewController.m
//  ExcellentHome
//
//  Created by liangxinqiang on 16/1/7.
//  Copyright © 2016年 陈区. All rights reserved.
//

#import "SEGMonthCardRecordViewController.h"
#import "MonthCardRequestModel.h"

@interface SEGMonthCardRecordViewController ()

@end

@implementation SEGMonthCardRecordViewController

-(void)loadView
{
    CGSize size = [[UIScreen mainScreen] bounds].size;
    UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
    self.view = mainView;
    
    self.tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height-44) style:UITableViewStyleGrouped];
    self.tableView.dataSource=self;
    self.tableView.delegate=self;
    self.tableView.backgroundColor=[UIColor clearColor];
    self.tableView.separatorColor=kColor_L2;
    [self.view addSubview:self.tableView];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"缴费记录";
    [self showCustomNavigationBackButton];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onRequest_UI:) name:NOTIFICATION_PAY_RECORD_LIST object:nil];
    
    [[MonthCardRequestModel sharedRequestModel] requestPayRecordList:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        NSDictionary *dict = result;
        
        if (!isSuccessed) { //数据返回异常
            [SEGAlertView showTmepMessageWithMessage:kNetworkErrorMessage];
        } else {
            self.dataArray = [NSArray arrayWithArray:[dict objectForKey:@"data"]];
            if ([self.dataArray count]>0) {
                [[SEGUhomeMediator sharedInstance] seg_hideCustomProgressImage:@{@"view":self.view}];
            } else{
                [[SEGUhomeMediator sharedInstance] seg_showCustomProgressImage:@{@"view":self.view}];
            }
            [self.tableView reloadData];
        }
    }];
}

#pragma mark -
#pragma mark
-(void)onRequest_UI:(NSNotification *)notification
{
    @try {
        NSDictionary *dict = [notification userInfo];
        if ([[dict valueForKey:@"code"] isEqualToString:@"0"]) {
            
            self.dataArray=[NSArray arrayWithArray:[dict objectForKey:@"data"]];
            
            if ([self.dataArray count]>0)
            {
                [[SEGUhomeMediator sharedInstance] seg_hideCustomProgressImage:@{@"view":self.view}];
            }else{
                [[SEGUhomeMediator sharedInstance] seg_showCustomProgressImage:@{@"view":self.view}];
            }
            [self.tableView reloadData];
        }
    }
    @catch (NSException *exception) {
    }
    @finally {
        //
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 65;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellStr=[NSString stringWithFormat:@"%d",(int)indexPath.row];
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellStr];
    
    if (cell==nil) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
        
        UILabel*titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(20, 15, CGRectGetWidth(self.tableView.bounds)-40, 20)];
        titleLabel.textColor=kColor_1;
        titleLabel.font=[UIFont systemFontOfSize:FONT_LIST_AND_DETAIL_SIZE];
        titleLabel.tag=100;
        [cell addSubview:titleLabel];
        
        UILabel*priceLabel=[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.tableView.bounds)-170, 15, 150, 20)];
        priceLabel.textColor=kColor_1;
        priceLabel.font=[UIFont systemFontOfSize:FONT_LIST_AND_DETAIL_SIZE];
        priceLabel.textAlignment=NSTextAlignmentRight;
        priceLabel.tag=101;
        [cell addSubview:priceLabel];
        
        
        UILabel*timeLabel=[[UILabel alloc] initWithFrame:CGRectMake(20, 40, CGRectGetWidth(self.tableView.bounds)-40, 20)];
        timeLabel.textColor=kColor_3;
        timeLabel.font=[UIFont systemFontOfSize:FONT_DESCRIPTION_SIZE];
        timeLabel.tag=102;
        [cell addSubview:timeLabel];
        
    }
    UILabel *titleLabel=(UILabel*)[cell viewWithTag:100];
    UILabel *priceLabel=(UILabel*)[cell viewWithTag:101];
    UILabel *timeLabel=(UILabel*)[cell viewWithTag:102];
    
    NSDictionary *dic=[self.dataArray objectAtIndex:indexPath.row];
    titleLabel.text=[dic objectForKey:@"plateNo"];
    priceLabel.text=[NSString stringWithFormat:@"%@元",[[dic objectForKey:@"payAmount"] stringValue]];
    timeLabel.text=[dic objectForKey:@"payDate"];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
